
MessageForm = Ext.extend(Ext.Panel, {
	constructor : function(_cfg) {
		Ext.applyIf(this, _cfg);
		this.initUIComponents();
		MessageForm.superclass.constructor.call(this, {
					id : 'MessageForm',
					layout : 'form',
					autoScroll:true,
					border : true,
					width : 460,
					height: 300,
					items : [this.formPanel]
				});
	},// end of constructor
	initUIComponents : function() {
		this.formPanel = new Ext.FormPanel({
			id : 'mFormPanel',
			title : '发送信息',
			iconCls : 'btn-sendM',
			frame : true,
			draggable : true,
			border : false,
			width : 460,
			style : 'margin-top:10%;margin-left:20%;',
			modal : true,
			layout : 'form',
			plain : true,
			scope : this,
			buttonAlign : 'center',
			items : [{
						xtype : 'hidden',
						name : 'userId',
						value: this.userId? this.userId:''
					}, {
						xtype : 'fieldcontainer',
						fieldLabel: '收信人',
						layout : 'hbox',
						items : [{
									xtype : 'textarea',
									name : 'userFullname',
									allowBlank : false,
									readOnly : true,
									value: this.userFullname?this.userFullname:'',
									width : 290
								}, {
									xtype : 'container',
									border : true,
									width : 100,
									heigth : 30,
									layout: 'vbox',
									items : [{
										xtype : 'button',
										iconCls : 'btn-mail_recipient',
										text : '添加联系人 ',
										width : 80,
										margin: '0 0 5 5',
										scope: this,
										handler : this.addUser
									}, {
										xtype : 'button',
										text : '清除联系人',
										iconCls : 'btn-del',
										width : 80,
										margin: '0 0 5 5',
										scope: this,
										handler : function() {
											var nameCmp = this.formPanel.getCmpByName('userFullname');
											var idCmp = this.formPanel.getCmpByName('userId');
											nameCmp.reset();
											idCmp.reset();
										}
									}]
								}]
					}, {
						fieldLabel: '内容',			
						xtype : 'textarea',
						name : 'content',
						height: 120,
						autoScroll:true,
						allowBlank : false
					}],
			buttons : [{
						text : '发送',
						iconCls : 'btn-mail_send',
						scope: this,
						handler :this.send
					}, {
						text : '重置',
						iconCls : 'reset',
						scope: this,
						handler :this.reset
					}]
		});

	},//end of initUIComponents
	send: function(){
		var me = this;
		$postForm({
				formPanel : this.formPanel,
				scope : this,
				url : __ctxPath + '/info/sendShortMessage.do',
				callback : function(fp, action) {
					Ext.ux.Toast.msg('操作信息', '信息发送成功！');
					me.formPanel.getForm().reset();
				}
			});
	},
	reset:function(){
	   this.formPanel.getForm().reset();
	},
	// 增加联系人
	addUser : function() {
		var me = this;
		UserSelector.getView(function(userIds, fullnames) {
					var userId = me.formPanel.getCmpByName('userId');
					var userFullname = me.formPanel.getCmpByName('userFullname');
					if (userId.getValue() != '' && userFullname.getValue() != '') {
						var stId = (userId.getValue() + ',').concat(userIds);
						var stName = (userFullname.getValue() + ',').concat(fullnames);
						var ids = uniqueArray(stId.split(','));
						var names = uniqueArray(stName.split(','));
						userId.setValue(ids.toString());
						userFullname.setValue(names.toString());
					} else {
						userId.setValue(userIds);
						userFullname.setValue(fullnames);
					}

				}).show();
	}
});
